package rickyGame.ui
{
	import com.resource.CursorRes;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.geom.Point;
	import flash.ui.Mouse;
	import flash.ui.MouseCursorData;

	/**
	 * 鼠标样式
	 */
	public class Cursor extends Bitmap
	{
		public function Cursor()
		{
//			var c:Bitmap=new CursorReSource.cursorMormal();
//			super(c.bitmapData);
		}
		
		/**
		 *攻击样式
		 */ 
		public static const ATTACK:String="attack";
		
		/**
		 * 对话样式
		 */ 
		public static const TALK:String="talk";
		
		/**
		 * 普通样式
		 */
		public static const NORMAL:String="normal";
		
		/**
		 * 魔法攻击样式
		 */
		public static const MAGIC:String="magic";
		
		/**
		 * 注册鼠标样式
		 */
		public static function register():void
		{
			//普通样式
			var normalData:MouseCursorData = new MouseCursorData;
			var normalBits:Vector.<BitmapData> = new Vector.<BitmapData>(1);
			normalBits[0] = Bitmap(new CursorRes.cursorMormal).bitmapData;
			normalData.data = normalBits;
			normalData.frameRate = 1;
			normalData.hotSpot = new Point(1,1);
			Mouse.registerCursor(Cursor.NORMAL,normalData);
			
			
			//攻击样式
			var attackData:MouseCursorData = new MouseCursorData;
			var attackBits:Vector.<BitmapData> = new Vector.<BitmapData>(1);
			attackBits[0] = Bitmap(new CursorRes.cursorAttack).bitmapData;
			attackData.data = attackBits;
			Mouse.registerCursor(Cursor.ATTACK,attackData);
			
			//魔法
			var magicData:MouseCursorData = new MouseCursorData;
			var magicBits:Vector.<BitmapData> = new Vector.<BitmapData>(1);
			magicBits[0] = Bitmap(new CursorRes.cursorMagic).bitmapData;
			magicData.data = magicBits;
			Mouse.registerCursor(Cursor.MAGIC, magicData);
			
			
			//对话样式
			var talkData:MouseCursorData = new MouseCursorData;
			var talkBits:Vector.<BitmapData> = new Vector.<BitmapData>(1);
			talkBits[0] = Bitmap(new CursorRes.cursorTalk).bitmapData;
			talkData.data = talkBits;
			Mouse.registerCursor(Cursor.TALK,talkData);
		}
		
		/**
		 * 显示鼠标样式
		 * cstyle 样式名
		 * lock是否锁定
		 */
		public static function show(cstyle:String = "normal", islock:Boolean = false):void
		{
			if(!lock)
			{
				Mouse.cursor = cstyle;
				_cursorState = cstyle;
			}
		}
		
		/**
		 * 释放鼠标样式锁定
		 */		
		public static function release():void
		{
			lock = false;
		}
		
		/**
		 * 变回鼠标默认样式
		 */
		public static function defaultStyle():void
		{
			show(NORMAL);
		}
		
		public static function get cursorState():String
		{
			return _cursorState;
		}
		
		public static var lock:Boolean = false;
		private static var _cursorState:String;
	}
}